package com.xzkydz.all_sensor.fragment;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.xzkydz.all_sensor.activity.MainActivity;
import com.xzkydz.all_sensor.allsensor.R;

/**
 * Created by Smilekun on 2016/8/30.
 */
public class RenCheFragment extends Fragment {

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View  view  =  inflater.inflate(R.layout.fragment_renche, container, false);
        final MainActivity mActivity  = (MainActivity)getActivity();
        final   EditText input  =  (EditText)view.findViewById(R.id.et_banjing_rc);
        Button  banjing  = (Button)view.findViewById(R.id.btn_banjing_rc);
        Button  startTime  = (Button)view.findViewById(R.id.btn_time_start);
        Button  acStart  = (Button)view.findViewById(R.id.btn_ac_start);
        Button  getMaxSpeed  = (Button)view.findViewById(R.id.btn_get_max_min);


        banjing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (input.getText().toString().length()==0){
                    Toast.makeText(mActivity,"请输入半径！" ,Toast.LENGTH_SHORT).show();
                }else{
                    float val  =  Float.parseFloat(input.getText().toString());
                    mActivity.radiou= val;
                    Toast.makeText(mActivity,"半径值为："+val,Toast.LENGTH_SHORT).show();
                }

            }
        });


        startTime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String completeData ="4B5908010500015100040159";
                mActivity.sendPortData(completeData);  //发送数据
                Toast.makeText(mActivity,"开始...",Toast.LENGTH_SHORT).show();
            }
        });


        acStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mActivity.sendPortData("4B590801050001A4010201AB");
                mActivity.ShowInf("加速度请求：");
                mActivity.list_acc.clear();
            }
        });

        getMaxSpeed.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mActivity.getMaxAndMin();
            }
        });


        return  view;
    }
}
